<template>
  <div class="head-container">
    <!-- 搜索 -->
    <div v-show="sup_this.searchToggle">
      <el-input v-model="paramBean.formName" clearable placeholder="输入名称搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="sup_this.toQuery"/>
      <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="sup_this.toQuery">搜索</el-button>
      <el-button class="filter-item" size="mini" type="warning" icon="el-icon-refresh-left" @click="sup_this.resetQuery()">重置</el-button>
    </div>
    <div class="crud-opts">
      <el-button
        v-permission="['SYS_ADMIN','COMMON_ADMIN','FORM_SET_ALL','FORM_SET_CREATE']"
        class="filter-item"
        size="mini"
        type="primary"
        icon="el-icon-plus"
        @click="doAdd">新增</el-button>
      <el-button
        v-permission="['SYS_ADMIN','COMMON_ADMIN','FORM_SET_ALL','FORM_SET_SUBMIT']"
        v-loading="submitLoading"
        class="filter-item"
        size="mini"
        type="success"
        icon="el-icon-check"
        @click="doMultiSubmit">提交</el-button>
      <el-button
        v-permission="['SYS_ADMIN','COMMON_ADMIN','FORM_SET_ALL','FORM_SET_CREATE']"
        class="filter-item"
        size="mini"
        type="primary"
        icon="el-icon-document-copy"
        @click="toCopy">复制</el-button>
      <el-button
        v-permission="['SYS_ADMIN','COMMON_ADMIN','FORM_SET_ALL','FORM_SET_DELETE']"
        v-loading="deleteLoading"
        class="filter-item"
        size="mini"
        type="danger"
        icon="el-icon-delete"
        @click="doMultiDelete">删除</el-button>
      <el-button
        v-permission="['SYS_ADMIN','COMMON_ADMIN','FORM_SET_ALL','FORM_SET_CHANGE']"
        class="filter-item"
        size="mini"
        type="primary"
        icon="el-icon-edit-outline"
        @click="toChange">变更</el-button>
      <DestoryOpt
        v-permission="['SYS_ADMIN','COMMON_ADMIN','FORM_SET_ALL','FORM_SET_DESTORY']"
        v-loading="destoryLoading"
        :sup_this="sup_this"
        @doMultiDestory="doMultiDestory">注销</DestoryOpt>
      <DataGridOpts :sup_this="sup_this" @refreshClick="refreshClick" @searchClick="searchClick" />
    </div>
  </div>
</template>

<script>
import eForm from './form'
import { submitUrl, deleteUrl, destoryUrl } from '@/api/system/formSet'

// 查询条件
export default {
  components: { eForm },
  props: {
    paramBean: {
      type: Object,
      required: true
    },
    sup_this: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      deleteLoading: false,
      changeLoading: false,
      submitLoading: false,
      destoryLoading: false
    }
  },
  methods: {
    refreshClick() {
      this.sup_this.init()
    },
    searchClick() {
      this.sup_this.toggleSearch()
    },
    beforeCreate() {
    },
    doMultiSubmit() {
      const _this = this.sup_this
      _this.doMultiSubmit(submitUrl(), this)
    },
    doMultiDelete() {
      const _this = this.sup_this
      _this.doMultiDelete(deleteUrl(), this)
    },
    doMultiDestory(selectIds, isSubmit) {
      const _this = this.sup_this
      _this.doMultiDestory(destoryUrl(), selectIds, isSubmit, this)
    },
    toCopy() {
      const _this = this.sup_this
      const selectMainId = _this.getSelectMainId()
      if (!selectMainId) {
        return
      }
      const _thisForm = _this.$refs.form
      _thisForm.initDataOfBefore()
      _thisForm.copyData(selectMainId)
    },
    toChange() {
      const _this = this.sup_this
      const selectBusId = _this.getSelectBusId()
      if (!selectBusId) {
        return
      }
      const _thisForm = _this.$refs.form
      _thisForm.initDataOfBefore()
      _thisForm.changeData(selectBusId)
    },
    doAdd() {
      const _this = this.sup_this.$refs.form
      _this.initDataOfBefore()
      _this.addData()
    }
  }
}
</script>
